
# test 1 => Get all tag names - COMPLETE
# test 2 => Get tag names in a tree structure


# Log for Day-to-Day
#
# 12 Dec 11
# 1. Need to keep going with a way to determine the building
#    of a stack to determine all the child tag names of each
#    tag that exist in the tree.
#   a. Create a stack that holds how deep we are in a current
#      tag structure.
#   b. Create a list of names for the current tag structure
#   c. Create a mechanism for setting the names of chilc tags
#      as deep as the current tag structure string calls for
#   d. Add a printing mechanism for printing all tags and their
#      child tags.

class XMLTag

  attr_accessor :name
  attr_accessor :childNames

  def initialize( name_in )

    @name = name_in
    @childNames = Array.new

  end

  def addChildTag( tag_path, child_tag_name )

end


class XMLParser

  def initialize( input_string )

    @xmlString = input_string
    @xmlTagNames = Array.new

    parserAlgorithm

  end

  def parserAlgorithm

    while nil != stripToNewName

    end

    puts
    puts "Tag Names Below"
    puts

    for tag in @xmlTagNames
      puts tag.name
    end

    puts

  end

  def stripToNewName

    # find tag opening
    stripTo = @xmlString.index "<"

    # found tag opening
    if nil != stripTo

      # strip to tag opening
      @xmlString.slice! 0..stripTo

      # find if the tag opening is a close tag
      if @xmlString.slice(0).chr != "/"

        # find space
        stripToSpace = @xmlString.index " "
        stripToClose = @xmlString.index ">"

        # find correct strip length for tag name
        if nil != stripToSpace and nil != stripToClose
          if stripToSpace < stripToClose
            stripTo = stripToSpace
          else
            stripTo = stripToClose
          end
        elsif nil != stripToSpace
          stripTo = stripToSpace
        elsif nil != stripToClose
          stripTo = stripToClose
        end


        # strip off new tag name
        tagNameBuff = @xmlString.slice! 0..(stripTo - 1)

        # push new name onto the array stack
        @xmlTagNames.push XMLTag.new tagNameBuff 

      else

        # use as a filler to keep machine going
        tagNameBuff = "filler"

      end

    else

      # return nil if end is found
      return nil

    end

    # return tag name to keep flow going
    return tagNameBuff

  end


end
